<?php
class ApiSginController extends ApiController
{
  private $rule = [
    '20181029' => 10, '20181030' => 20, '20181031' => 40,
    '20181101' => 70, '20181102' => 100, '20181103' => 140, '20181104' => 180,
    '20181105' => 10, '20181106' => 20, '20181107' => 40,
    '20181108' => 70, '20181109' => 100, '20181111' => 140,
  ];

  public function ruleAction()
  {
    return $this->okReturn($this->rule);
  }

  public function indexAction()
  {
    $signResult = boolval($this->account->sgin());
    if ($signResult) {
      $this->account->sigin_seriate_times++;
      //TODO 测试 添加积分
      if ($flowders = $this->rule[date('Ymd', REQUEST_TIME)] ?? 10) {
        $changeResult = $this->account->chageFlowers('签到', $flowders, date('Y年m月d日', REQUEST_TIME) . ' 签到');
      }
     //TODO 连续签到
      return $this->okReturn([ 'flowers' => $changeResult ? $flowders ?? 0 : 0 ]);
    } else {
      return $this->errorReturn('您今日已经签到');
    }
  }

  public function recordAction()
  {
    $page = max(intval($this->req->getQueryTrim('page', 1)), 1);
    $rows = intval($this->req->getQueryTrim('rows', 15));
    return $this->okReturn(['list' => $this->account->getSginRecordsList([
      'allWithKeyDate' => true
    ], $page, $rows)]);
  }

}